package com.zapletalovi.tests;

import javax.annotation.Resource;
import javax.ejb.*;
import java.util.Date;

@Stateless
@Remote(ExampleTimer.class)
@Local(ExampleTimer.class)
public class ExampleTimerBean implements ExampleTimer {
    @Resource
    private SessionContext ctx;

    public void scheduleTimer(long milliseconds) {
        ctx.getTimerService().createTimer(new Date(new Date().getTime() + milliseconds), "Hello World");
    }

    @Timeout
    public void timeoutHandler(Timer timer) {
        System.out.println("---------------------");
        System.out.println("* Received Timer event: " + timer.getInfo());
        System.out.println("---------------------");

        timer.cancel();
    }
}